<?php
#基础函数
include_once('_path.php');
include_once("../includes/init.php");
#样式
$css = array();
$js = array();
#菜单
$menu = "members";

#uid
$uid = intval($_GET['uid']);

include_once("../layout/_header.php");
?>
        <div class="main">
       		<div class="traininc-nav-list">
				<ul>
                                <li><a href="<?= _CONST_BACKEND_URL ?>/members/edit.php?action=view.form&id=<?=$uid ?>">基本信息</a></li>
                                <li><a href="<?= _CONST_BACKEND_URL ?>/files/index.php?uid=<?=$uid?>">文件上传</a></li>
                                <li><a href="<?= _CONST_BACKEND_URL ?>/message/index.php?uid=<?=$uid?>">留言管理</a></li>
                                <li class="selected"><a href="javascript:">绑定会员卡</a></li>
				</ul>
			</div>
            			<div class="box-con">
                                    <form action="edit.php?action=cardadd.do&uid=<?=$uid?>" method="post" id="form" name="form" enctype="multipart/form-data">
				<table class="table-input">
                                    <?php
                                    #获取绑定卡;
                                    $rs = $database->queryFirst("SELECT * FROM members_card WHERE uid = $uid");
                                    if($rs['id']>0 && $rs['status']!='2'){
                                    ?>
                                    <tr>
						<td class="title">已经绑定</td>
						<td><span style="font-size:24px; color:red;padding-right:20px"><?=$rs['card']?></span>
                                                <?php
                                                if($rs['status'] == '1'){
                                                ?>
                                                    [<a href="edit.php?action=cardunbind.do&uid=<?=$uid?>&id=<?=$rs['id']?>">解除绑定</a>]
                                                <?php
                                                }else{
                                                ?>
                                                    [<a href="edit.php?action=cardbind.do&uid=<?=$uid?>&id=<?=$rs['id']?>">设为主卡号</a>]
                                                <?php
                                                }
                                                ?>
                                                </td>
			            </tr>
                                    <?php
                                    }elseif($rs['id']>0 && $rs['status']=='2'){
                                    ?>
					<tr>
						<td><?=$rs['card']?>卡已经被绑定为副卡</td>
					</tr>
                                   <?php
                                    }else{
                                    ?>
					<tr>
						<td class="title">输入卡号</td>
						<td><input type="text" size="50" name="card" value="" >   <input type="submit" name="" value="绑定" class="btnA" /></td>
					</tr>
                                    <?php
                                    }
                                    ?>
				</table>
                                </form>
                                <?php
                                if($rs['status'] == '1'){
                                ?>
				<h3>管理您的副卡</h3>
                                <form action="edit.php?action=cardinfoadd.do&uid=<?=$uid?>&id=<?=$rs['id']?>" method="post" id="form2" name="form2">
				<table class="table-input">
					<tr>
						<td class="title">输入卡号</td>
						<td><input type="text" size="50" name="card" value="" >   <input type="submit" name="" value="添加" class="btnA" /></td>
					</tr>
				</table>
                                </form>
                                <?php
                                #获得副卡信息
                                $fs = array();
                                $fs = $database->queryArray("SELECT mc.*,mi.name,mi.id as id FROM members_card mc LEFT JOIN members_info mi ON mi.id = mc.uid WHERE pid =".$rs['id']);
                                ?>
				<table class="table-blue">
					<thead>
						<tr>
							<th>编号</th>
							<th>卡号</th>
							<th>姓名</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
				<?
                                for($i=0;$i<sizeof($fs);$i++){
                                $r = $fs[$i];
                                $j = 1;
                                ?>
                                    <tr <?=iif($j%2==0, 'class="odd"')?>>
							<td><?=$r['id']?></td>
							<td><?=$r['card']?></td>
							<td><?=$r['name']?></td>
                                                        <td><a href="<?=_CONST_BACKEND_URL?>members/edit.php?action=view.form&id=<?= $r['id'] ?>">查看详细</a> | <a href="edit.php?action=del.do&uid=<?=$uid?>&id=<?=$id?>">解除绑定</a></td>
						</tr>
                                        <?
                                        $j++;
                                        }
                                        ?>
					</tbody>
				</table>
                                <?php
                                    }
                                ?>
			</div>
        </div>
<?
include_once("../layout/_footer.php");
?>